﻿# Injected Html code for charts generation
$strChartName = "MyChart"

$strTopHtml = @"
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Visifire Charts</title>
    </head>
    <body>
        <script type="text/javascript" src="../XapFiles/Visifire2.js"></script>
        <div id="div$strChartName">
        <script language="javascript" type="text/javascript">
        var chartXmlString = ''
        +'<vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts" '
            +' Width="@width@" Height="@heigth@" View3D="False" BorderThickness="0" Theme="Theme1" AnimationEnabled="True">'
        +'<vc:Chart.Titles>'
        +'<vc:Title Text="@ChartName@"/>'
        +'</vc:Chart.Titles>'
        +'<vc:Chart.AxesX>'
        +'<vc:Axis Interval="1" Title="@xLabel@"/>'
        +'</vc:Chart.AxesX>'
        +'<vc:Chart.AxesY>'
        +'<vc:Axis Title="@yLabel@"/>'
        +'</vc:Chart.AxesY>'
        +'<vc:Chart.Series>'        
"@

$strBottomHtml = @"
    +'</vc:Chart.Series>'
    +'</vc:Chart>';
    var $strChartName = new Visifire2("../XapFiles/SL.Visifire.Charts.xap",@width@,@heigth@);
    $strChartName.setDataXml(chartXmlString);
    $strChartName.render("div$strChartName");
    </script>
    </div>
    </body>
    </html>
"@
    
function out-visifire($objData)
{
    # Add Top HTML Code
    $strOutput += $strTopHtml
  
    # Create Each Visifire DataSets
    foreach ($HashSource in $objData) {  
        $strOutput += "`r+'<vc:DataSeries RenderAs=`"@type@`" >'`r";
        $strOutput += "+'<vc:DataSeries.DataPoints>'`r";
          
        $HashSource.GetEnumerator()|%{
            $key = $_.name;$value = $_.value;        
            $strOutput += "+'<vc:DataPoint AxisXLabel=`"$key`" YValue=`"$value`"/>'`r";
        }

        # Close DataSerie
        $strOutput += "+'</vc:DataSeries.DataPoints>'`r";
        $strOutput += "+'</vc:DataSeries>'`r"
    }
            
    # Add Bottom HTML Code
    $strOutput += $strBottomHtml       
    
    # return Generated HTML
    return $strOutput
 }  